package part15;

/**
 * @author wcj
 * @Date 2021/5/28 20:10
 * @Version 1.0
 */
public class Part153 {

    static TwoTuple<String, Integer> f() {
        return new TwoTuple<>("hi", 47);
    }

    static ThreeTuple<Amphibian, String, Integer> g() {
        return new ThreeTuple<>(new Amphibian(), "hi", 47);
    }

    static FourTuple<Vehicle, Amphibian, String, Integer> h() {
        return new FourTuple<>(new Vehicle(), new Amphibian(), "hi", 47);
    }

    static FiveTuple<Vehicle, Amphibian, String, Integer, Double> k() {
        return new FiveTuple<>(new Vehicle(), new Amphibian(), "hi", 47, 3.14);
    }

    /**
     * 第一，元组即一个将一组对象打包存储的单一对象，只能够读取对象，无法改变对象的值。
     * 第二，元组的出现，解决呢java中方法无法返回多个值的情况
     * 第三，元组的元素最好不使用private定义，而是使用public final进行修饰
     * 第四，因为元组的元素不可改动，所以我们只能使用继承的方式继承其它元组从而新增元组元素
     *
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(f());
        System.out.println(g());
        System.out.println(h());
        System.out.println(k());
    }

}

class Amphibian {
}

class Vehicle {
}

class TwoTuple<A, B> {
    public final A first;
    public final B second;

    public TwoTuple(A a, B b) {
        this.first = a;
        this.second = b;
    }

    @Override
    public String toString() {
        return first + "," + second;
    }
}

class ThreeTuple<A, B, C> extends TwoTuple<A, B> {

    public final C third;

    public ThreeTuple(A a, B b, C c) {
        super(a, b);
        this.third = c;
    }

    @Override
    public String toString() {
        return first + "," + second + "," + third;
    }
}

class FourTuple<A, B, C, D> extends ThreeTuple<A, B, C> {

    public final D fourth;

    public FourTuple(A a, B b, C c, D d) {
        super(a, b, c);
        this.fourth = d;
    }

    @Override
    public String toString() {
        return first + "," + second + "," + third + "," + fourth;
    }
}

class FiveTuple<A, B, C, D, E> extends FourTuple<A, B, C, D> {
    public final E fifth;

    public FiveTuple(A a, B b, C c, D d, E e) {
        super(a, b, c, d);
        this.fifth = e;
    }

    @Override
    public String toString() {
        return first + "," + second + "," + third + "," + fourth + "," + fifth;
    }
}
